<template>
	<view class="order-record">
		<nav-bar :title="title"></nav-bar>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="preview(item)">
				<view class="left">
					<view class="number"><text class="label">订单号：</text>{{item.order_num}}</view>
					<view class="time"><text class="label">录单日期：</text>{{item.createtime_text}}</view>
				</view>
				<view class="preview" v-if="type == 1">查看</view>
				<view class="preview" v-else>{{item.status | formatStatus}}</view>
			</view>
		</view>
		<view class="back-btn" v-if="type === 2">返回首页</view>
	</view>
</template>

<script>
	import {
		orderRecordListApi
	} from "@/api/store.js"
	export default {
		data() {
			return {
				list: [],
				type: 1,
				title: '',
				status: 2
			}
		},
		filters: {
			formatStatus(val) {
				let str = ""
				switch (val) {
					case 1:
						str = "待审核"
						break
					case 2:
						str = "已审核"
						break
				}
				return str
			}
		},
		onLoad(opt) {
			this.type = opt.type || 1
			this.title = opt.type == 1 ? '录单记录' : '审核记录'
			this.status = opt.status || 2
		},
		onShow() {
			this.getData()
		},
		methods: {
			preview(item) {
				if (this.type == 2) {
					//审核人员
					this.$Router.push(`/pages/store/order-examine/order-examine?id=${item.id}`)
				} else {
					this.$Router.push(`/pages/store/order-entry/order-entry?id=${item.id}&type=${this.type}`)
				}

			},
			async getData() {
				let form = {
					type: this.type,
				}
				if (this.type == 2) {
					form.status = this.status
				}
				let {
					data
				} = await orderRecordListApi(form)
				this.list = data
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'index.scss';
</style>
